package com.da.javatest.interview.session1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author chenlida
 * @date 2020/3/25 19:09
 * @description 方法的引用传递，String与包装类的不可变性
 */
public class Test04 {
    public static void main(String[] args) {
        int i = 1;
        String s = "hello";
        Integer n = 100;
        int[] ints = {1, 2, 3, 4, 5};
        MyData myData = new MyData();

        change(i, s, n, ints, myData);

        System.out.println(i);
        System.out.println(s);
        System.out.println(n);
        System.out.println(Arrays.toString(ints));
        System.out.println(myData.a);

        System.out.println("===========================");

        List<MyData> list = Arrays.asList(new MyData(1), new MyData(2), new MyData());
        List<MyData> list2 = change2(list);
        System.out.println(list);
        System.out.println(list2);

        System.out.println("===========================");

        List<MyData> list3 = new ArrayList<>();
        list3.add(new MyData(7));
        list3.add(new MyData(8));
        list3.add(new MyData(9));
        change3(list3);
        System.out.println(list3);
    }

    private static void change(int i, String s, Integer n, int[] ints, MyData myData) {
        i += 1;
        s += "world";
        n += 100;
        ints[0] += 1;
        myData.a += 1;
    }

    private static List<MyData> change2(List<MyData> list) {
        list = list.stream().filter(x -> x.a != 10).collect(Collectors.toList());
        System.out.println("change2 list:" + list);
        return list;
    }

    private static void change3(List<MyData> list) {
        list.remove(2);
    }

}

@NoArgsConstructor
@AllArgsConstructor
@ToString
class MyData {
    int a = 10;
}